<template>
  <div class="sort_container flex">
    <div class="menu_row flex">
      <div class="row_item" :class="{
        select: sort == index + 1
      }" v-for="(item, index) in list" :key="index" @click="changeSort(index)">{{ item }}</div>
    </div>
    <div class="category_select flex" @click="showSelectorHandler">
      <van-icon name="filter-o" size="15px" color="#a3acc8" />
      <span v-show="!show">筛选</span>
      <span v-show="show">收起</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue"

/* 接收参数 */
const props = defineProps<{
  list: string[]
  sort: number
}>()

/* 接收自定义事件 */
const emits = defineEmits<{
  (e: "changeSort", sortStr: number): void
}>()

/* 定义响应式数据 */
let show = ref(false)

/* 点击筛选的回调 */
const showSelectorHandler = () => {
  show.value = !show.value
}

/* 点击排序的回调 */
const changeSort = (index: number) => {
  emits("changeSort", index + 1)
}


</script>

<style lang="less" scoped>
.sort_container {
  width: 375px;
  height: 44px;
  padding-left: 15px;
  box-sizing: border-box;
  align-items: center;

  .menu_row {
    width: 70%;

    .row_item {
      width: 82px;
      height: 28px;
      margin: 8px 4px 8px 0;
      padding: 6px 10px;
      font-size: 14px;
      color: #a3a3ac;
      box-sizing: border-box;
      border-radius: 15px;
    }

    .select {
      border: 1px solid #f86442;
      color: #f86442;
    }
  }

  .category_select {
    box-sizing: border-box;
    height: 27px;
    padding: 6px 12px;
    margin-left: 10px;
    border-radius: 13.5px;
    background-color: #f3f4f5;

    span {
      margin-left: 5px;
      font-size: 12px;
      line-height: 18px;
      color: #a3acc8;
    }
  }
}
</style>